package com.pfsoft.service.impl;/**
 * 文章管理实现类
 *
 * @author PF
 * Created by dell on 2017-09-26.
 */

import com.pfsoft.JapRepository.ArticleRepository;
import com.pfsoft.model.Article;
import com.pfsoft.query.ArticleQuery;
import com.pfsoft.service.IArticleManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * com.pfsoft.service.impl
 * 文章管理实现类
 * @author PF
 * @create 2017-09-26 11:51
 **/
@Service
public class ArticleManagerImpl implements IArticleManager {

    @Autowired
    private ArticleRepository articleRepository;


    @Override
    public Page<Article> getArticles(ArticleQuery queryCondition) throws  Exception{
        return articleRepository.findAll(this.buildPageRequest(queryCondition));
    }

    //构建PageRequest
    private PageRequest buildPageRequest(ArticleQuery queryCondition) {

        return new PageRequest(queryCondition.getPageNo() - 1, queryCondition.getPageSzie(), null);
    }
}
